package text_2023_09_24;

import java.io.*;

/**
 * @author Vv
 * @version 1.0
 * @project coding_learn
 * @description
 * @date 2023/9/24 22:45:26
 */
public class CopyPngToD {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            fileInputStream = new FileInputStream("c:/1/jpg");
            fileOutputStream = new FileOutputStream("d:/2.jpg");
            byte[] b = new byte[1024];
            int a = 0;
            while(true){
                a = fileInputStream.read(b);
                if(a == -1){
                    break;
                }
                fileOutputStream.write(b,0,a);
            }
            fileOutputStream.flush();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if(fileInputStream != null){
                fileInputStream.close();
            }
            if(fileOutputStream != null){
                fileOutputStream.close();
            }
        }
    }

    public static void main1(String[] args) throws IOException {
        BufferedWriter bufferedWriter = null;
        BufferedReader bufferedReader = null;
        FileWriter fw = new FileWriter("c:/1.jpg");
        FileReader fr = new FileReader("d:/2.jpg");
        try {

            bufferedReader = new BufferedReader(fr);
            bufferedWriter = new BufferedWriter(fw);
            while(true){
                String content = bufferedReader.readLine();
                if(content != null){
                   // System.out.println("读到了一行，开始写入");
                    bufferedWriter.write(content);
                    bufferedWriter.newLine();
                }else{
                    System.out.println("拷贝完成");
                    break;
                }
            }

        }catch (IOException e){

        }finally {
            fw.close();
            fr.close();
            bufferedReader.close();
            bufferedWriter.close();
        }



    }
}
